﻿using UnityEngine;
using System.Collections;

namespace UI
{
    public class RushBuyAdditionItem : MonoBehaviour
    {
        public AloneTextureKit icon;
        public UILabel attrLabel;
        public UILabel addValueLabel;
        public UILabel costValueLabel;
        public GameObject selectHandler;

        int costValue;
        string addition;

        public string GetAddition() {
            return addition;
        }

        public int GetCostValue() {
            return costValue;
        }

        public void Init(string addition, int costValue, bool select = false) {
            this.addition = addition;
            this.costValue = costValue;

            var arr = addition.Split(new char[1] { ',' }, System.StringSplitOptions.RemoveEmptyEntries);
            if (arr.Length == 2)
            {
                attrLabel.text = RushPage.ParseAttributeAdditionName(arr[0]); 
                float val = float.Parse(arr[1]);
                addValueLabel.text = string.Format("+{0}%", (val * 100).ToString("f0"));
                icon.SetPath(@"RushAddIcon/" + arr[0]);
            }
            else {
                attrLabel.text = "";
                addValueLabel.text = "";
            }

            costValueLabel.text = costValue.ToString();
            selectHandler.SetActive(select);
        }

        public void Select() {
            selectHandler.SetActive(true);
        }

        public void UnSelect() {
            selectHandler.SetActive(false);
        }
    }

}